<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>初始化 state - 紫霞仙子</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //设置数据
        class App extends React.Component{
            state = {
                isNight: true
            }

            //2. 设置回调
            change = () => {
                //setState 方法接收对象类型的数据, 更新state中的状态数据
                this.setState({
                    isNight: !this.state.isNight
                })
            }

            render(){
                return <div>
                        <h2>至尊宝, 我是{this.state.isNight ? '青霞仙子' : '紫霞仙子'}</h2>
                        {/**1. 绑定事件*/}
                        <button onClick={this.change}>点击切换白天与黑夜</button>
                    </div>
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>